<?php
    header("content-type:text/html;charset=utf8");
    $username = $_POST['username'];
    $password = $_POST['password'];
    $tel = $_POST['tel'];
    $email = $_POST['email'];
    $con = mysqli_connect('localhost','root','root','info');
    $res = mysqli_query($con,"select * from user where username = '$username'");
    $row = mysqli_fetch_assoc($res);
    if($row) {
        $arr = [
            "meta" => [
                "status" => 101,
                "msg" => "用户名已被占用"
            ],
            "data" => null
        ];
    }else {
        $res = mysqli_query($con,"insert into user(username,password,tel,email) values ('$username','$password',$tel,'$email')");
        if($res) {
            $arr = [
                "meta" => [
                    "status" => 102,
                    "msg" => "注册成功"
                ],
                "data" => null
            ]; 
        }else {
            $arr = [
                "meta" => [
                    "status" => 103,
                    "msg" => "注册失败"
                ],
                "data" => null
            ];
        }
    }
    echo json_encode($arr);